package com.jeeplus.netty;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import org.mozilla.javascript.debug.DebuggableObject;

import java.util.List;

public class MessagePacketDecoder extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
        System.out.println(buffer);
           if (buffer.readableBytes() > 0) {
                // 待处理的消息包
                byte[] bytesReady = new byte[buffer.readableBytes()];
                buffer.readBytes(bytesReady);
                String s = new String(bytesReady);

                System.out.println("MessagePacketDecoder == " + s);

                out.add(buffer.readByte());

            }
        }
    }